#include <stdio.h>
int main()
{
    int a,b,c[100],n;
    while (scanf("%d%d",&a,&b)!=EOF)
    {
        n=0;
        if (a<0){a=-a;printf("-");}
        while (a)
        {
            c[n++]=a%b;
            a/=b;
        }
        while (n--)
        {
            if (c[n]>=10)printf("%c",c[n]-10+'A');
            else printf("%d",c[n]);
        }
        printf("\n");
    }
    return 0;
}